<?php


namespace App\Imports;

use App\Models\Schedule;
use Illuminate\Http\Response;
use Maatwebsite\Excel\Concerns\Importable;
use Maatwebsite\Excel\Concerns\SkipsFailures;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Maatwebsite\Excel\Concerns\WithStartRow;

/**
 * Created By FreeAbrams
 * Date: 2020/11/27
 */
class SchedulesImports implements ToModel, WithStartRow
{
	use Importable, SkipsFailures;
	
	protected $import_time = '';
	
	function __construct($import_time)
	{
		$this->import_time = $import_time;
	}
	
	public function startRow(): int
	{
		return 5;
	}
	
	public function model(array $row)
	{
		$store_id = \Encore\Admin\Facades\Admin::user()->store_id;
		// 共 34列
		return new Schedule([
			'store_id' => $store_id,
			'import_time' => $this->import_time,
			'staff_id' => $row[0],
		    'name' => $row[1],
		    'department' => $row[2],
	        'one' => $row[3],
			'two' => $row[4],
			'three' => $row[5],
			'four' => $row[6],
			'five' => $row[7],
			'six' => $row[8],
			'seven' => $row[9],
			'eight' => $row[10],
			'nine' => $row[11],
			'ten' => $row[12],
            'eleven' => $row[13],
            'twelve' => $row[14],
            'thirteen' => $row[15],
            'fourteen' => $row[16],
            'fifteen' => $row[17],
            'sixteen' => $row[18],
            'seventeen' => $row[19],
            'eighteen' => $row[20],
            'nineteen' => $row[21],
            'twenty' => $row[22],
            'twenty_one' => $row[23],
            'twenty_two' => $row[24],
            'twenty_three' => $row[25],
            'twenty_four' => $row[26],
            'twenty_five' => $row[27],
            'twenty_six' => $row[28],
            'twenty_seven' => isset($row[29])?$row[29]:null,
            'twenty_eight' => isset($row[30])?$row[30]:null,
            'twenty_nine' => isset($row[31])?$row[31]:null,
            'thirty' => isset($row[32])?$row[32]:null,
            'thirty_one' => isset($row[33])?$row[33]:null,
		]);
	}
}